<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;

/* @var $this yii\web\View */
/* @var $model app\models\Task */
/* @var $form yii\widgets\ActiveForm */
?>
<style type="text/css">
    div.task-form label {
        margin: 0.1em 1.5em;
    }

    tr.task_tr {
        display: none;
    }
</style>

<div class="task-form">

    <?php $form = ActiveForm::begin(); ?>

    <table class="layui-table">
        <tr style="background-color: #ccc;">
            <td style="text-align: right;">
                年-月:
            </td>
            <td style="text-align: left;">
                <input type="text" id="lay_month" name="month" value="<?= $next_month ?>" <?= $this->context->action->id == 'update' ? 'disabled="disabled"' : '' ?> />
            </td>
        </tr>
        <tr>
            <td colspan="2" style="text-align: center;">
                <?php foreach ($user_array as $jobname => $users) { ?>
                    <label><input type="checkbox" value="<?= $jobname ?>" onchange="window.select_jobname(this)" /> <?= $jobname ?></label>
                <?php } ?>
            </td>
        </tr>
        <?php $index = 1;
        foreach ($user_array as $jobname => $users) {
            foreach ($users as $u) { ?>
                <tr class="task_tr" name="<?= $jobname ?>">
                    <input type="hidden" name="task[<?= $index ?>][user_id]" value="<?= $u['id'] ?>" />
                    <td style="text-align: right;"><?= $u['name'] ?>：</td>
                    <td><input style="width: 100%;" type="number" name="task[<?= $index ?>][task_num]" value="<?= $u['task_num'] ?>" /></td>
                </tr>
        <?php
                $index++;
            }
        } ?>
    </table>

    <div class="form-group" style="text-align: right;">
        <?= Html::submitButton('保存', ['class' => 'btn btn-success']) ?>
    </div>

    <?php ActiveForm::end(); ?>

</div>
<script type="text/javascript">
    window.select_jobname = function(obj) {
        if (obj.checked) {
            $('tr.task_tr[name="' + obj.value + '"]').show();
        } else {
            $('tr.task_tr[name="' + obj.value + '"]').hide();
        }
    }
    window.jobname_init = function() {
        <?php if ($this->context->action->id == 'update') { ?>
            $('input[type="checkbox"]').attr('checked', 'checked');
            $('tr.task_tr').show();
        <?php } else { ?>
            $('tr.task_tr[name="咨询人员"]').show();
            $('input[value="咨询人员"]').attr('checked', true);
            layui.laydate.render({
                elem: '#lay_month',
                type: 'month',
                min: '<?= $next_month ?>-20'
            });
        <?php } ?>

    }
    window.setTimeout("window.jobname_init()", 200);
</script>